package com.mzx.info.controller;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mzx.entity.BaseDict;
import com.mzx.entity.Customer;
import com.mzx.entity.Info;
import com.mzx.info.service.InfoService;

@Controller
@RequestMapping("/Info")
public class InfoController {
	@Autowired
	private InfoService infoService;

	/* 登录成功加载新建信息下拉列表 */
	@RequestMapping("/loadinfo.action")
	public String loadinfo(HttpSession session, Customer customer) {
		List<BaseDict> logo = infoService.LoadInfo("002");
		List<BaseDict> clour = infoService.LoadInfo("001");
		List<BaseDict> place = infoService.LoadInfo("003");

		session.setAttribute("logo", logo);
		session.setAttribute("clour", clour);
		session.setAttribute("place", place);
		
		return "forward:/Info/info.action";

	}

	/* 加载维修信息 */
	@RequestMapping("/info.action")
	public String list(Info info,HttpSession httpSession,Customer customer,Model model) {
		System.out.println(customer);
		info = infoService.getInfo(customer);
		
		model.addAttribute("info", info);
		
		return "home";
	}

	/* 创建维修信息 */
	@PostMapping("/createInfo.action")
	@ResponseBody

	public Boolean createInfo(Info info) {
		
		
		Date date=new Date();
		
		info.setInfo_state("20");
		info.setInfo_createtime(date);
		System.out.println(info);
		return infoService.createInfo(info);

	}
				/*查询修改框定位到的值*/
@RequestMapping("showInfo.action")
@ResponseBody
public  Info showCustomer(String  info_customer_carcode,Info info) {
	info=infoService.showInfo(info_customer_carcode);
	System.out.println(info);
	  return info;
	
}
			/*修改维修信息*/
@RequestMapping("changeInfo.action")
@ResponseBody
public Boolean changeInfo(Info info) {
	System.out.println(info);
	Date date = new Date();
	info.setInfo_createtime(date);
	return infoService.changeInfo(info);
	
	
}
			/*维修信息删除模块*/
@RequestMapping("/removeInfoByCarcode.action")
@ResponseBody
public Boolean deleteInfo(String info_customer_carcode) {
	return infoService.deleteInfo(info_customer_carcode);
			 
	
}
}
